home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / Demos / Duel / gameproc.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-31  |  6.7 KB  |  222 lines

  1. //-----------------------------------------------------------------------------
  2. // File: GameProc.h
  3. //
  4. // Desc: Game processing routines
  5. //
  6. // Copyright (C) 1995-2001 Microsoft Corporation. All Rights Reserved.
  7. //-----------------------------------------------------------------------------
  8. #define IDIRECTPLAY2_OR_GREATER
  9. #include <ddraw.h>
  10. #include <dplay.h>
  11. #include <dsound.h>
  12.  
  13. // align on single byte boundaries
  14. // this is a stop-gap measure until the structures can be re-arranged.
  15. #pragma pack(1)
  16.  
  17. #define MAX_SHIP_X     (MAX_SCREEN_X - 32)
  18. #define MAX_SHIP_Y     (MAX_SCREEN_Y - 32)
  19. #define MAX_SHIP_FRAME 40
  20. #define MAX_BULLET_X    (MAX_SCREEN_X - 3)
  21. #define MAX_BULLET_Y    (MAX_SCREEN_Y - 3)
  22. #define MAX_BULLET_FRAME 400
  23.  
  24. #define NUM_SHIP_TYPES 4
  25.  
  26. #define DEF_SHOW_DELAY     (2000)
  27. #define MAX_BUFFER_SIZE    256
  28.  
  29. #define UPDATE_INTERVAL     40      // interval between position updates in milliseconds (25 FPS)
  30. #define SYNC_INTERVAL       1000    // synchronize once every second
  31. #define HIDE_TIMEOUT        5000    // time for which a ship is disabled after a hit
  32.  
  33. // Keyboard commands
  34. #define KEY_STOP        0x00000001l
  35. #define KEY_DOWN        0x00000002l
  36. #define KEY_LEFT        0x00000004l
  37. #define KEY_RIGHT       0x00000008l
  38. #define KEY_UP          0x00000010l
  39. #define KEY_FIRE        0x00000020l
  40. #define KEY_ENGINEOFF   0x00000040l
  41.  
  42. // Offsets for the bullet bitmap
  43. #define     BULLET_X    304
  44. #define     BULLET_Y    0
  45.  
  46. struct FRAG
  47. {
  48.     double      dPosX;
  49.     double      dPosY;
  50.     LPDIRECTDRAWSURFACE pdds;
  51.     RECT        src;
  52.     double      dVelX;
  53.     double      dVelY;
  54.     BOOL        valid;
  55. };
  56.  
  57. struct SHIP
  58. {
  59.     double              dPosX, dPosY;               // ship x and y position
  60.     double              dBulletPosX, dBulletPosY;   // bullet x and y position
  61.     DWORD               dwBulletFrame;              // bullet frame
  62.     char                cFrame;                     // current ship frame
  63.     BYTE                byType;                     // ship type 
  64.     BOOL                bEnable;                    // is this ship active?
  65.     BOOL                bBulletEnable;              // Is there an active bullet?
  66.  
  67.     double              dVelX, dVelY;               // ship x and y velocity (pixels/millisecond)
  68.     double              dBulletVelX, dBulletVelY;   // bullet x and y velocity (pixels/millisecond)
  69.     DWORD               dwScore;                    // current score
  70.     DWORD               dwLastTick;                 // most recent time stamp
  71.     BOOL                bIgnore;                    // flag used to synchronize ship explosions
  72.     int                 iCountDown;                 // enable time-out            
  73.     DWORD               dwFrameCount;               // number of frames since beginning of time
  74.  
  75.     // DSound members 
  76.     DWORD                 dwKeys;                  // the keyboard state
  77.     BOOL                  bEngineRunning;          // These BOOLs keep track of the ship's
  78.     BOOL                  bMoving;                 //   last condition so we can play sounds
  79.     BOOL                  bBounced;                //   when they change
  80.     BOOL                  bBlockHit;
  81.     BOOL                  bDeath;
  82.     BOOL                  bFiring;
  83. };
  84.  
  85. struct BLOCKS
  86. {
  87.     BYTE bits[30][5];
  88. };
  89.  
  90.  
  91.  
  92.  
  93. //-----------------------------------------------------------------------------
  94. // communication packet structures
  95. //-----------------------------------------------------------------------------
  96. #define MSG_HOST        0x11    // message containing field layout, sent by host
  97. #define MSG_BLOCKHIT    0x22    // block hit message
  98. #define MSG_SHIPHIT     0x33    // ship hit message
  99. #define MSG_ADDBLOCK    0x44    // add block message
  100. #define MSG_CONTROL     0x55    // game keys message
  101. #define MSG_SYNC        0x66    // synchronization message containing the rendezvous location
  102.  
  103. struct GENERICMSG
  104. {
  105.     BYTE byType;
  106. };
  107.  
  108. struct OLDHOSTMSG
  109. {
  110.     BYTE byType;
  111.     BLOCKS Blocks;
  112. };
  113.  
  114. struct HOSTMSG
  115. {
  116.     BYTE        byType;
  117.     BLOCKS      Blocks;
  118.     int         usedShipTypes[NUM_SHIP_TYPES];
  119. };
  120.  
  121. struct BLOCKHITMSG
  122. {
  123.     BYTE        byType;
  124.     BYTE        byRow;
  125.     BYTE        byCol;
  126.     BYTE        byMask;
  127. };
  128.  
  129. struct SHIPHITMSG
  130. {
  131.     BYTE        byType;
  132.     DPID        Id;
  133. };
  134.  
  135. struct ADDBLOCKMSG
  136. {
  137.     BYTE        byType;
  138.     BYTE        byX;
  139.     BYTE        byY;
  140. };
  141.  
  142. struct CONTROLMSG
  143. {
  144.     BYTE        byType;
  145.     BYTE        byState;
  146. };
  147.  
  148. struct SYNCMSG
  149. {
  150.     BYTE        byType;
  151.     BYTE        byShipType;     // this is needed only when sends are unreliable
  152.     char        cFrame;
  153.     double      dPosX;
  154.     double      dPosY;
  155. };
  156.  
  157.  
  158.  
  159.  
  160. //-----------------------------------------------------------------------------
  161. // Prototypes
  162. //-----------------------------------------------------------------------------
  163. VOID    LaunchGame();
  164. VOID    ExitGame();
  165. HRESULT InitOurShip();
  166.  
  167. HRESULT InitLocalSoundData();
  168. BOOL WINAPI SetPlayerLocalSoundDataCB( DPID dpId, DWORD dwPlayerType,
  169.                                        LPCDPNAME pName, DWORD dwFlags,
  170.                                        VOID* pContext );
  171.  
  172. VOID    ReleaseLocalData();
  173. VOID    ReleasePlayerLocalSoundData( SHIP* pShip );
  174. BOOL WINAPI ReleasePlayerLocalDataCB( DPID dpId, DWORD dwPlayerType,
  175.                                       LPCDPNAME pName, DWORD dwFlags,
  176.                                       VOID* pContext );
  177.  
  178. VOID    UpdateState( SHIP* pShip, DWORD dwControls );
  179. VOID    SendSync( SHIP* pShip );
  180. VOID    UpdateDisplayStatus( SHIP* pShip );
  181. VOID    UpdatePosition( DPID dpId, SHIP* ship );
  182. BOOL    IsHit( int x, int y );
  183. VOID    InitField();
  184. BOOL    setBlock( int x, int y );
  185. VOID    AddFrag( SHIP* pShip, int offX, int offY );
  186. VOID    UpdateFragment( int i );
  187. VOID    DestroyShip( SHIP* pShip );
  188. VOID    DestroyGame();
  189. BOOL    UpdateFrame();
  190.  
  191. VOID    ProcessSoundFlags( SHIP* pShip );
  192. BOOL WINAPI RenderPlayerCB( DPID dpId, DWORD dwPlayerType, LPCDPNAME pName, 
  193.                             DWORD dwFlags, VOID* pContext );
  194. BOOL    DrawScreen();
  195. BOOL    DrawScore();
  196. VOID    DrawShip( SHIP* pShip );
  197. VOID    DrawBlock( int x, int y );
  198. VOID    DrawBullet( SHIP* pShip );
  199. VOID    DrawFragments();
  200. VOID    DisplayFrameRate();
  201.  
  202. VOID    GetConnection();
  203. HRESULT ReceiveMessages();
  204. VOID    DoSystemMessage( DPMSG_GENERIC* pMsg, DWORD dwMsgSize, DPID idFrom,
  205.                          DPID idTo );
  206. VOID    DoApplicationMessage( GENERICMSG* pMsg, DWORD dwMsgSize, DPID idFrom,
  207.                               DPID idTo );
  208. VOID    SendGameMessage( GENERICMSG* pMsg, DPID idTo );
  209. VOID    CleanupComm();
  210.  
  211.  
  212. HRESULT InitializeGameSounds();
  213. VOID    CleanupGameSounds();
  214.  
  215.  
  216.  
  217. // restore default alignment
  218. #pragma pack()
  219.  
  220.  
  221.  
  222.